/* eslint-disable no-return-await */
import Taro from '@tarojs/taro'
import { http } from '@pier88health/p8h-common'
import { getPlatform } from '@UTILS/common'
import { getStorageSync } from '@UTILS/localStorage'
import { axios } from 'taro-axios'
import DBConfig from '@CONFIG/DBConfig'

const { fetchRequest } = http
const getToken = async () => await getStorageSync('token')
const platform = getPlatform()
const isUseProxy = process.env.NODE_ENV === 'development' && platform.isWeb
http.init({
  // eslint-disable-next-line no-undef
  baseUrl: isUseProxy ? '/wmp' : `${BASE_URL}/wmp`,
  // baseUrl: `/wmp`,
  axios,
  logEnable: DBConfig.careEnvType !== 'prod',
  enableCacheToken: true,
  errorKey: platform.isWeb ? 'error' : 'Error',
  getToken
})
const apiService = {
  getCode: fetchRequest('/User/DevTest', 'GET'),
  checkConsulationStatus: fetchRequest('/User/CheckConsulationStatus', 'GET'),
  getVersionStatus: fetchRequest('/PubClient/CheckStatus', 'GET'),
  createUser: fetchRequest('/PubClient/CheckStatus', 'GET'),
  loginWithWeXinData: fetchRequest('/User/LoginWithWeXinData', 'POST'),
  loginWithWeChatInfo: fetchRequest('/User/LoginWithWeChatInfo', 'POST'),
  requestAuthCode: fetchRequest('/User/RequestAuthCode', 'POST'),
  loginOrRegisterByPhone: fetchRequest('/User/LoginOrRegisterByPhone', 'POST'),
  loginByPhone: fetchRequest('/User/LoginByPhone', 'POST'),
  getWeChatOpenId: fetchRequest('/User/GetWeChatOpenId', 'GET'),
  visitorLogin: fetchRequest('/User/VisitorLogin', 'POST'),
  getPatientRelationship: fetchRequest('/Patient/GetRelationship', 'GET'),
  getUserMatchedTags: fetchRequest('/Patient/GetUserMatchedTags', 'GET'),
  getPatientSource: fetchRequest('/Patient/PatientSourceDropdown', 'GET'),
  getMyPatients: fetchRequest('/Patient/GetMyPatients', 'GET'),
  getMyPatientsAndRegistrationStatus: fetchRequest('/Patient/GetMyPatientsAndRegistrationStatus', 'GET'),
  getPatientById: fetchRequest('/Patient/GetPatientById', 'GET'),
  savePatient: fetchRequest('/Patient/Save', 'POST'),
  register: fetchRequest('/Patient/Register', 'POST'),
  registerFromSurveyQrCode: fetchRequest('/Patient/RegisterFromSurveyQrCode', 'POST'),
  getDoctors: fetchRequest('/Doctor/GetDoctors', 'GET'),
  getDoctorsByTagIds: fetchRequest('/Doctor/GetDoctorsByTagIds', 'GET'),
  getCustomDoctors: fetchRequest('/Doctor/GetCustomDoctors', 'GET'),
  getQuickInquiryDoctors: fetchRequest('/Doctor/GetQuickInquiryDoctors', 'GET'),
  getRecommendDoctors: fetchRequest('/Doctor/GetRecommendDoctors', 'GET'),
  getDoctorDetail: fetchRequest('/Doctor/GetDoctorDetail', 'GET'),
  getDoctorPracticeInfo: fetchRequest('/Doctor/GetDoctorPracticeInfo', 'GET'),
  getWxServiceNoticeTemplate: fetchRequest('/Notification/GetWxServiceNoticeTemplate', 'GET'),
  getNewsFeed: fetchRequest('/FeedItem/GetNewsFeed', 'GET'),
  getNewsFeedByTagIds: fetchRequest('/FeedItem/GetNewsFeedByTagIds', 'GET'),
  getNewsFeedByTagIds_V2: fetchRequest('/FeedItem/GetNewsFeedByTagIds_V2', 'GET'),
  getMatchedNewsFeed: fetchRequest('/FeedItem/GetMatchedNewsFeed', 'GET'),
  getRelatedTagsByName: fetchRequest('/Tag/GetRelatedTagsByName', 'GET'),
  getTopicByCode: fetchRequest('/Topic/GetTopicByCode', 'GET'),
  getFeedItemsByDoctorId: fetchRequest('/FeedItem/GetFeedItemsByDoctorId', 'GET'),
  getFeedItemDetail: fetchRequest('/FeedItem/GetFeedItemDetail', 'GET'),
  getSessions: fetchRequest('/Chat/GetSessions', 'GET'),
  getSessions2: fetchRequest('/Chat/GetSessions2', 'GET'),
  getBellAlerts: fetchRequest('/Notification/GetBellAlerts', 'GET'),
  markRead: fetchRequest('/Notification/MarkRead', 'POST'),
  enterSessionById: fetchRequest('/Chat/EnterSessionById2', 'POST'),
  enterCareChatSessionByMemberIds: fetchRequest('/Chat/EnterSessionByMemberIds', 'POST'),
  enterSessionByConsultationId: fetchRequest('/Chat/EnterSessionByConsultationId2', 'POST'),
  createMessage: fetchRequest('/Chat/CreateMessage', 'POST'),
  getMessages: fetchRequest('/Chat/GetMessages2', 'GET'),
  clearCareChatHistory: fetchRequest('/Chat/ClearHistory', 'POST'),
  clearCareChatNewMessageNumberInSession: fetchRequest('/Chat/ClearNewMessageNumberInSession', 'GET'),
  enterSessionByUserIds: fetchRequest('/Chat/EnterSessionByUserIds', 'POST'),
  getNewBellAlertsNumber: fetchRequest('/Notification/GetNewBellAlertsNumber', 'GET'),
  getMessageById: fetchRequest('/Chat/GetMessageById', 'GET'),
  setAudioPlayed: fetchRequest('/Chat/SetAudioPlayed', 'POST'),
  recognizeVoiceByUrl: fetchRequest('/Chat/RecognizeVoiceByUrl', 'POST'),
  requestOssToken: fetchRequest('/Sts/RequestOssToken', 'GET'),
  requestRAMRole: fetchRequest('/Sts/RequestRAMRole', 'GET'),
  getSearchPredictions: fetchRequest('/Search/GetSearchPredictions', 'GET'),
  globalSearch: fetchRequest('/Search/GlobalSearch', 'GET'),
  getMyDoctors: fetchRequest('/Patient/GetMyDoctors', 'GET'),
  getDefaultPatient: fetchRequest('/Patient/GetDefaultPatient', 'GET'),
  saveWeChatNoticeStates: fetchRequest('/NoticeState/SaveWeChatNoticeStates', 'POST'),
  getAllNewNotification: fetchRequest('/Notification/GetAllNewNotification', 'GET'),
  getConsultationById: fetchRequest('/Consultation/GetConsultationById', 'GET'),
  getConsultationDetail: fetchRequest('/Consultation/GetConsultationDetail', 'GET'),
  getMyConsultations: fetchRequest('/Consultation/GetMyConsultations', 'GET'),
  getMyOrders: fetchRequest('/Order/GetMyOrders', 'GET'),
  getMyConsultationOrders: fetchRequest('/Order/GetMyConsultationOrders', 'GET'),
  getOrderPaymentHistory: fetchRequest('/Order/GetOrderPaymentHistory', 'GET'),
  cancelMyOrder: fetchRequest('/Order/CancelMyOrder', 'POST'),
  setZeroOrderAsPaid: fetchRequest('/Order/SetZeroOrderAsPaid', 'POST'),
  startConsultation: fetchRequest('/Consultation/StartConsultation', 'POST'),
  checkExisting: fetchRequest('/Consultation/CheckExisting', 'GET'),
  getExistingConsultation: fetchRequest('/Consultation/GetExistingConsultation', 'GET'),
  initiatePayment: fetchRequest('/Payment/InitiatePayment', 'POST'),
  weChatOrderQuery: fetchRequest('/Payment/WeChatOrderQuery', 'GET'),
  initiatePaymentMock: fetchRequest('/Payment/InitiatePaymentMock', 'POST'),
  getOrderById: fetchRequest('/Order/GetOrderById', 'GET'),
  createRating: fetchRequest('/Rating/CreateRating', 'POST'),
  existsUserRating: fetchRequest('/Rating/ExistsUserRating', 'GET'),
  getDoctorRatings: fetchRequest('/Rating/GetDoctorRatings', 'GET'),
  getMedicineDetail: fetchRequest('/Medicine/GetMedicineDetail', 'GET'),
  updateUserByWeChatInfo: fetchRequest('/Profile/UpdateUserByWeChatInfo', 'POST'),
  updateUserProfile: fetchRequest('/Profile/UpdateUserProfile', 'POST'),
  setUserAvatarVersion: fetchRequest('/Profile/SetUserAvatarVersion', 'POST'),
  getLandingProfile: fetchRequest('/Profile/LandingProfile', 'GET'),
  createPainLog: fetchRequest('/PainLog/Create', 'POST'),
  editPainLog: fetchRequest('/PainLog/Edit', 'POST'),
  getLatestPainLog: fetchRequest('/PainLog/GetLatestPainLog', 'GET'),
  getPainLogs: fetchRequest('/PainLog/GetPainLogs', 'GET'),
  medicineSearch: fetchRequest('/Medicine/MedicineSearch', 'GET'),
  getPainLogDetail: fetchRequest('/PainLog/GetPainLogDetail', 'GET'),
  getPainLogOptions: fetchRequest('/PainLog/GetOptions', 'GET'),
  getAllOptions: fetchRequest('/PainLog/GetAllOptions', 'GET'),
  getSelfPatient: fetchRequest('/Patient/GetSelfPatient', 'GET'),
  getActiveSessionByDocUserId: fetchRequest('/Chat/GetActiveSessionByDocUserId', 'GET'),
  getPopupEventByUserId: fetchRequest('/Popup/GetPopupEventByUserId', 'GET'),
  getGroupDetail: fetchRequest('/Group/GetGroupDetail', 'GET'),
  getDecisionFlows: fetchRequest('/DecisionFlow/GetDecisionFlows', 'GET'),
  startJouney: fetchRequest('/DecisionFlow/StartJouney', 'POST'),
  makeChoice: fetchRequest('/DecisionFlow/MakeChoice', 'POST'),
  moveToStep: fetchRequest('/DecisionFlow/MoveToStep', 'POST'),
  getPainLogSummaryByPId: fetchRequest('/PainLog/GetPainLogSummaryByPId', 'GET'),
  getMostPainSitesByPId: fetchRequest('/PainLog/GetMostPainSitesByPId', 'GET'),
  getMostPainTriggersByPId: fetchRequest('/PainLog/GetMostPainTriggersByPId', 'GET'),
  getPainLogFactorSummaryByPatientId: fetchRequest('/PainLog/GetPainLogFactorSummaryByPatientId', 'GET'),
  getEventsListBySpotCode: fetchRequest('/OpEvent/GetEventsListBySpotCode', 'GET'),
  getEventsListBySpotCodes: fetchRequest('/OpEvent/GetEventsListBySpotCodes', 'GET'),
  scanCodeLog: fetchRequest('/Log/ScanCodeLog', 'POST'),
  requestBaiduToken: fetchRequest('/Sts/RequestBaiduToken', 'GET'),
  getSignatureUrl: fetchRequest('/Sts/GetSignatureUrl', 'POST'),
  getTotalNewMessageNumber: fetchRequest('/Chat/GetTotalNewMessageNumber', 'GET'),
  updateUnionId: fetchRequest('/Profile/UpdateUnionId', 'POST'),
  getSurveyTemplates: fetchRequest('/Survey/GetSurveyTemplates', 'GET'),
  getSurveyById: fetchRequest('/Survey/GetSurveyById', 'GET'),
  startSurvey: fetchRequest('/Survey/Start', 'POST'),
  submitSurvey: fetchRequest('/Survey/Submit', 'POST'),
  getMyLastSurveyByTemplate: fetchRequest('/Survey/GetMyLastSurveyByTemplate', 'GET'),
  getPainLogDaySummaryByDate: fetchRequest('/PainLog/GetPainLogDaySummaryByDate', 'GET'),
  getStatesByCountryCode: fetchRequest('/Geo/GetStatesByCountryCode', 'GET'),
  getCitiesByStateOrCountryCode: fetchRequest('/Geo/GetCitiesByStateOrCountryCode', 'GET'),
  getPrescriptionDetail: fetchRequest('/Prescription/GetPrescriptionDetail', 'GET'),
  getMyPrescriptions: fetchRequest('/Prescription/GetMyPrescriptions', 'GET'),
  getMyDistinctFlowsNumber: fetchRequest('/DecisionFlow/GetMyDistinctFlowsNumber', 'GET'),
  getMySurveyTemplatesNumber: fetchRequest('/Survey/GetMySurveyTemplatesNumber', 'GET'),
  getMyLastJourneyResultsByDecisionFlows: fetchRequest('/DecisionFlow/GetMyLastJourneyResultsByDecisionFlows', 'GET'),
  getMyLastSurveysByTemplates: fetchRequest('/Survey/GetMyLastSurveysByTemplates', 'GET'),
  getMyLastJourneyByDecisionFlowId: fetchRequest('/DecisionFlow/GetMyLastJourneyByDecisionFlowId', 'GET'),
  getJourneyResultById: fetchRequest('/DecisionFlow/GetJourneyResultById', 'GET'),
  getFlowNode: fetchRequest('/DecisionFlow/GetFlowNode', 'GET'),
  generateScheme: fetchRequest('/WeChat/GenerateScheme', 'POST'),
  getRecommendDoctorsHome: fetchRequest('/Doctor/GetRecommendDoctorsHome', 'GET'),
  getCourses: fetchRequest('/Course/GetCourses', 'GET'),
  getCoursesByTag: fetchRequest('/Course/GetCoursesByTag', 'GET'),
  getCoursesByTagIds: fetchRequest('/Course/GetCoursesByTagIds', 'GET'),
  getCourseDetail: fetchRequest('/Course/Browse', 'GET'),
  getRelatedCourses: fetchRequest('/Course/GetRelatedCourses', 'GET'),
  playCourse: fetchRequest('/Course/Play', 'POST'),
  stopCourse: fetchRequest('/Course/Stop', 'POST'),
  getMyCoupons: fetchRequest('/Coupon/GetMyCoupons', 'GET'),
  getMyCouponList: fetchRequest('/Coupon/GetMyCouponList', 'GET'),
  getCouponDetailByRefValue: fetchRequest('/Coupon/GetCouponDetailByRefValue', 'GET'),
  getCouponDetailByAggregateQuery: fetchRequest('/Coupon/GetCouponDetailByAggregateQuery', 'GET'),
  getTemplates: fetchRequest('/ServicePack/GetTemplates', 'GET'),
  orderServicePack: fetchRequest('/ServicePack/Order', 'POST'),
  renewServicePack: fetchRequest('/ServicePack/Renew', 'POST'),
  selectDoctor: fetchRequest('/ServicePack/SelectDoctor', 'POST'),
  getTemplateById: fetchRequest('/ServicePack/GetTemplateById', 'GET'),
  getTemplatesAndPacks: fetchRequest('/ServicePack/GetTemplatesAndOptions', 'GET'),
  getTemplateOptionsDetail: fetchRequest('/ServicePack/GetTemplateOptionsDetail', 'GET'),
  selectPatients: fetchRequest('/ServicePack/SelectPatients', 'POST'),
  getServicePackDetail: fetchRequest('/ServicePack/GetServicePackDetail', 'GET'),
  updatePackSurvey: fetchRequest('/ServicePack/UpdatePackSurvey', 'POST'),
  getServiceItemDetail: fetchRequest('/ServicePack/GetServiceItemDetail', 'GET'),
  getPackByCode: fetchRequest('/ServicePack/GetPackByCode', 'GET'),
  getDecisionFlowById: fetchRequest('/DecisionFlow/GetDecisionFlowById', 'GET'),
  getSurveyTemplateById: fetchRequest('/Survey/GetSurveyTemplateById', 'GET'),
  getMatchedSurveyTemplates: fetchRequest('/Survey/GetMatchedSurveyTemplates', 'GET'),
  getTagById: fetchRequest('/Tag/GetTagById', 'GET'),
  getTagByName: fetchRequest('/Tag/GetTagByName', 'GET'),
  getRecommendDoctorsTopic: fetchRequest('/Doctor/GetRecommendDoctorsTopic', 'GET'),
  getNewsFeedByTag: fetchRequest('/FeedItem/GetNewsFeedByTag', 'GET'),
  getMyLastConsultation: fetchRequest('/Consultation/GetMyLastConsultation', 'GET'),
  reUploadPictureFile: fetchRequest('/Consultation/ReUploadPictureFile', 'POST'),
  getMyServicePacks: fetchRequest('/ServicePack/GetMyServicePacks', 'GET'),
  getMyServicePackOrders: fetchRequest('/Order/GetMyServiceManagementOrders', 'GET'),
  getTemplatesByClient: fetchRequest('/ServicePack/GetTemplatesByClient', 'GET'),
  getSurveyTemplateAndDeceisionFlowByTag: fetchRequest('/Tag/GetSurveyTemplateAndDeceisionFlowByTag', 'GET'),
  getManagementTemplate: fetchRequest('/PainManagement/GetManagementTemplate', 'GET'),
  getManagementTemplates: fetchRequest('/PainManagement/GetManagementTemplates', 'GET'),
  getPainManagementSummary: fetchRequest('/PainManagement/GetPainManagementSummary', 'GET'),
  getPainManagementsHistory: fetchRequest('/PainManagement/GetPainManagementsHistory', 'GET'),
  startPainManagement: fetchRequest('/PainManagement/StartPainManagement', 'POST'),
  getMyPainManagement: fetchRequest('/PainManagement/GetMyPainManagement', 'GET'),
  setDailyContentViewed: fetchRequest('/PainManagement/SetDailyContentViewed', 'POST'),
  getTemplatesByTagIds: fetchRequest('/PainManagement/GetTemplatesByTagIds', 'GET'),
  startJourney: fetchRequest('/Bot/StartJourney', 'POST'),
  botInput: fetchRequest('/Bot/Input', 'POST'),
  getPlanById: fetchRequest('/FollowUpPlan/GetPlanById', 'GET'),
  getTodayPainLogSummary: fetchRequest('/PainLog/GetTodayPainLogSummary', 'GET'),
  saveWeChatStepRecords: fetchRequest('/PainManagement/SaveWeChatStepRecords', 'POST'),
  getTodayWeChatStepRecord: fetchRequest('/PainManagement/GetTodayWeChatStepRecord', 'GET'),
  getMeditations: fetchRequest('/Meditation/GetMeditations', 'GET'),
  getMeditation: fetchRequest('/Meditation/Browse', 'GET'),
  getMyMeditationSummary: fetchRequest('/Meditation/GetMySummary', 'GET'),
  getSharableMeditation: fetchRequest('/Meditation/GetSharableMeditation', 'GET'),
  playMeditation: fetchRequest('/Meditation/Play', 'POST'),
  stopMeditation: fetchRequest('/Meditation/Stop', 'POST'),
  shareMeditation: fetchRequest('/Meditation/Share', 'POST'),
  getGoodsByTagIds: fetchRequest('/Goods/GetGoodsByTagIds', 'GET'),
  getMyAddresses: fetchRequest('/Address/GetMyAddresses', 'GET'),
  getAddressById: fetchRequest('/Address/GetAddressById', 'GET'),
  updateMyAddress: fetchRequest('/Address/Update', 'POST'),
  createMyAddress: fetchRequest('/Address/Create', 'POST'),
  archiveAddress: fetchRequest('/Address/Archive', 'POST'),
  getGoodsBySKUNames: fetchRequest('/Goods/GetGoodsBySKUNames', 'GET'),
  getRecommendGoods: fetchRequest('/Goods/GetRecommendGoods', 'GET'),
  getMatchedGoods: fetchRequest('/Goods/GetMatchedGoods', 'GET'),
  getParcelState: fetchRequest('/Logistics/GetParcelState', 'GET'),
  painManagementRecord: fetchRequest('/Log/PainManagementRecord', 'POST'),
  updateUserInvitor: fetchRequest('/User/UpdateUserInvitor', 'POST'),
  getMyExpiredPainManagementList: fetchRequest('/PainManagement/GetMyExpiredPainManagementList', 'GET'),
  getPainManagementResult: fetchRequest('/PainManagement/GetPainManagementResult', 'GET'),
  getMyLastestExpiredPainManagement: fetchRequest('/PainManagement/GetMyLastestExpiredPainManagement', 'GET'),
  intelligentAddress: fetchRequest('/Address/IntelligentAddress', 'GET'),
  getMyPopup: fetchRequest('/Popup/GetMyPopup', 'GET'),
  getMyInvites: fetchRequest('/Invite/GetMyInvites', 'GET'),
  saveMyInviter: fetchRequest('/Invite/SaveMyInviter', 'POST'),
  inquire: fetchRequest('/Patient/Inquire', 'POST'),
  getPatientMedRecords: fetchRequest('/Patient/GetPatientMedRecords', 'GET'),
  getConsultationReports: fetchRequest('/Patient/GetConsultationReports', 'GET'),
  setConsultationReportViewed: fetchRequest('/Patient/SetConsultationReportViewed', 'GET'),
  countUnViewedConsultationReport: fetchRequest('/Patient/CountUnViewedConsultationReport', 'GET'),
  getMyRecommendPainManagements: fetchRequest('/PainManagement/GetMyRecommendPainManagements', 'GET'),
  getAndSortRecommendPainManagements: fetchRequest('/PainManagement/GetAndSortRecommendPainManagements', 'GET'),
  getSystemConfig: fetchRequest('/User/SystemConfig', 'GET'),
  uploadMyPatientMedRecords: fetchRequest('/Patient/UploadMyPatientMedRecords', 'POST'),
  deletePatientMedRecord: fetchRequest('/Patient/DeletePatientMedRecord', 'POST'),
  getMedRecordVisitTime: fetchRequest('/MedRecord/GetPatientMedRecords', 'GET'),
  getMedRecord: fetchRequest('/MedRecord/GetMedRecord', 'GET'),
  getOrStartMedRecord: fetchRequest('/MedRecord/GetOrStartMedRecord', 'GET'),
  medRecordConsent: fetchRequest('/MedRecord/Consent', 'POST'),
  saveField: fetchRequest('/MedRecord/SaveField', 'POST'),
  movePart: fetchRequest('/MedRecord/MovePart', 'POST'),
  medRecordSubmit: fetchRequest('/MedRecord/Submit', 'POST'),
  setAppStatus: fetchRequest('/Log/SetAppStatus', 'POST'),
  getMyPainLogsByDateBucket: fetchRequest('/PainLog/GetMyPainLogsByDateBucket', 'GET'),
  deleteMyPainLog: fetchRequest('/PainLog/DeleteMyPainLog', 'POST'),
  getPatientMonthPainLog: fetchRequest('/PainLog/GetPatientMonthPainLog', 'GET'),
  saveMenstruationLogs: fetchRequest('/PainLog/SaveMenstruationLogs', 'POST'),
  getPainLogMonthCountByPId: fetchRequest('/PainLog/GetPainLogMonthCountByPId', 'GET'),
  getPainManagementOrder: fetchRequest('/PainManagement/GetPainManagementOrder', 'GET'),
}

export default apiService
